package org.example.springcloud.service;

import com.github.pagehelper.PageHelper;
import org.example.springcloud.util.PageResultUtil;
import org.example.springcloud.bean.PageResult;
import org.example.springcloud.bean.PageParam;
import org.example.springcloud.dao.UserDao;
import org.example.springcloud.entities.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserDao userDao;

    @Override
    public boolean addUser(User user) {
        return userDao.insertUser(user);
    }

    @Override
    public User getUser(Long userid) {
        User user = userDao.findUserByUserId(userid);
        System.out.println(user);
        return user;
    }

    @Override
    public PageResult<User> getList(PageParam<User> pageParam) {
        PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
        User user = pageParam.getFormParam();
        if (!user.getDate().isEmpty()) {
            user.setBegindate(user.getDate().get(0));
            user.setEndddate(user.getDate().get(1));
        }
        List<User> list = userDao.queryUser(user);
        return PageResultUtil.getPageResult(list);
    }
}
